#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H

#include "PDBManager.h"

class AlignmentInfo;
class RenderWindow;
class ResidueWindow;
class SequenceWindow;
class FileRequest;
struct RenderData;

class MainWindow : public wxFrame
{
private:
	wxTimer RequestTimer;

	wxSplitterWindow *vSplitter;
	wxSplitterWindow *hSplitter;

	wxPanel *renderWindowFrame;
	RenderWindow **renderWindows;
	int numRenderWindows;

	ResidueWindow *residueWindow;
	SequenceWindow *sequenceWindow;
	PDBManager *pdbManager;

	FileRequest *request;

	// Used internally by constructor only.  Creates all subwindows,
	// but does not make visible (Constructors do so, however).
	void InitMainWindow();

	// Runs alignment.  Ignores new window flag (As handled before calling),
	// but pays attention to others.  Also handles cleanup of info, in case
	// ever add threading.
	void RunAlignment(AlignmentInfo *info);
public:
	MainWindow(const wxString &path = wxEmptyString);
	MainWindow(AlignmentInfo *info);


	SharedStatusBar *statusBar;

	// Refresh = 0 if about to load file, to prevent immediate redraw.
	// Refresh = 1 if not about to load file.
	// Note that it will create a new PDBManager, if the old one was shared.
	void ClearPDB(int refresh);

	int LoadPDB(const wxString &path, int requireEnd, const wxString &wxStringExtraComment = wxEmptyString);
	void Redraw(unsigned int flags = REDRAW_ALL, int chain=-1, int residue=-1);

	void OnOpen(wxCommandEvent& evt);
	void OnOpenNew(wxCommandEvent& evt);
	void OnOpenWeb(wxCommandEvent& evt);
	void OnExit(wxCommandEvent& evt);
	void OnChangeViz(wxCommandEvent& evt);
	void OnChangeCamera(wxCommandEvent& evt);
	void OnChangeColor(wxCommandEvent& evt);
	void OnToggleSetting(wxCommandEvent& evt);

	void OnAlignment(wxCommandEvent& evt);
	void OnSettings(wxCommandEvent& evt);

	void OnSelectAll(wxCommandEvent& evt);

	void OnUndo(wxCommandEvent& evt);
	void OnAbout(wxCommandEvent& evt);

	void OnToggleWindow(wxCommandEvent& evt);

	void OnClose(wxCloseEvent& evt);

	void ToggleResidueWindow();
	void ToggleSequenceWindow();

	int UpdateRequest();
	void OnRequestTimer(wxTimerEvent &evt);

	bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);

	void UpdateChecks();

	void OnActivate(wxActivateEvent& evt);
	void OnSize(wxSizeEvent& evt);

	void OnSplitterEvent(wxSplitterEvent& evt);

	~MainWindow();

	void CleanupRequest();

	void ContextMenu();

	void ChangeSelection(int chain, int index);
	int LoadAlignment(MultipleAlignment *ma, int flags);

	void UpdatePDBManager(PDBManager *manager, int index, int flags, RenderData **renderData);
	void SetDefaultDisplayModes();

	void AddRenderWindow(int restrictChain=-1, int labelChain=0);
	void LayoutRenderWindows();

	void CompleteRequest(FileRequest *request);

	DECLARE_EVENT_TABLE()
};

#endif
